import * as API from '@/api/home.js';

export default {
  namespaced: true,
  state() {
    return {
      userList: [],
      movieList: [],
      cinemaList: [],
      hallList: [],
      movieScheduleList: [],
      movieCommentList: [],
      orderList: [],
    };
  },
  mutations: {
    SET_USER_LIST(state, payload) {
      state.userList = payload;
    },
    SET_MOVIE_LIST(state, payload) {
      state.movieList = payload;
    },
    SET_CINEMA_LIST(state, payload) {
      state.cinemaList = payload;
    },
    SET_HALL_LIST(state, payload) {
      state.hallList = payload;
    },
    SET_MOVIE_SCHEDULE_LIST(state, payload) {
      state.movieScheduleList = payload;
    },
    SET_MOVIE_COMMENT_LIST(state, payload) {
      state.movieCommentList = payload;
    },
    SET_ORDER_LIST(state, payload) {
      state.orderList = payload;
    },
  },
  actions: {
    async updateUserList({ commit }) {
      const res = await API.getUserList();
      commit('SET_USER_LIST', res);
    },
    async updateMovieList({ commit }) {
      const res = await API.getMovieList();
      commit('SET_MOVIE_LIST', res);
    },
    async updateCinemaList({ commit }) {
      console.log(1);
      const res = await API.getCinemaList();
      commit('SET_CINEMA_LIST', res);
    },
    async updateHallList({ commit }) {
      const res = await API.getHallList();
      commit('SET_HALL_LIST', res);
    },
    async updateMovieScheduleList({ commit }) {
      const res = await API.getMovieScheduleList();
      commit('SET_MOVIE_SCHEDULE_LIST', res);
    },
    async updateMovieCommentList({ commit }) {
      const res = await API.getMovieCommentList();
      commit('SET_MOVIE_COMMENT_LIST', res);
    },
    async updateOrderList({ commit }) {
      const res = await API.getOrderList();
      commit('SET_ORDER_LIST', res);
    },
  },
};
